const DB = require('../../../../utils/db')
/**
 * POST
 * 新增一个评论
 */
module.exports = async (ctx) => {
  let params = ctx.request.body

  // 往评论表插入一条记录
  const res = await DB.query(
    `insert into  dynamic_comment(userid, createTime, dynamicId, commentContent, toReply) values('${params.userid}', now(), '${params.dynamicId}', '${params.commentContent}', '${params.toReply}')`
  )
  
  // 帖子表对应帖子评论数+1, 并且重置更新时间
 const res1 = await DB.query(
   `update dynamic set commentTotal = commentTotal + 1, updateTime = now() where id = '${params.dynamicId}'`
 )

  ctx.body = {
    code: 0,
    mes: '评论成功',
  }
}
